package com.example.pc.updata.DaTi;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.example.pc.http.API;
import com.example.pc.http.KB_Adapter;
import com.example.pc.http.Okhttp;
import com.example.pc.updata.ChengJis;
import com.example.pc.updata.KeBiao;
import com.example.pc.updata.R;
import com.example.pc.utils.JSONUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by ADM on 2017/12/2.
 * 我的课程表
 */

public class wdKBList_activity extends FragmentActivity {


    @BindView(R.id.img_back)
    RelativeLayout imgBack;
    @BindView(R.id.button2)
    Button button2;
    @BindView(R.id.lv_list)
    ListView lvList;
    @BindView(R.id.title)
    TextView title;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_chengji);
        ButterKnife.bind(this);
        title.setText("我的成绩");
        initViewsAndEvents();
        getCurriculums();
    }

    KB_Adapter bank_card_adapter;

    public void initViewsAndEvents() {
        RelativeLayout img_back = (RelativeLayout) findViewById(R.id.img_back);//设置;
        img_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        ListView lvList = (ListView) findViewById(R.id.lv_list);//设置;
        lvList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {


            }
        });

        bank_card_adapter = new KB_Adapter();
        lvList.setAdapter(bank_card_adapter);


    }

    List<ChengJis.DataBean> ccList = new ArrayList<>();


    public void getCurriculums() {
        ccList.clear();
        API.getmyCurriculums(wdKBList_activity.this, new Okhttp.Objectcallback() {
            @Override
            public void onsuccess(String st) {
                Log.e("111", "xx" + st);
                ChengJis teacher = JSONUtils.parseJSON(st, ChengJis.class);
                if (teacher.isIssuccess() == true) {

                    ccList = teacher.getData();
                    if (ccList != null && ccList.size() > 0) {
                        bank_card_adapter.addItem(ccList);
                    } else {
                        Toast.makeText(wdKBList_activity.this, "数据为空！", Toast.LENGTH_SHORT).show();
                    }


                } else {
                    Toast.makeText(wdKBList_activity.this, teacher.getMsg(), Toast.LENGTH_SHORT).show();

                }
            }

            @Override
            public void onFalia(int code, String errst) {
                Toast.makeText(wdKBList_activity.this, "网络错误！", Toast.LENGTH_SHORT).show();
            }
        });
    }


    @OnClick({R.id.img_back, R.id.button2, R.id.button3})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_back:
                finish();
                break;
            case R.id.button3:
//                startActivity(new Intent(this, MyXuanKe_Activity.class));
                break;
            case R.id.button2:
//                startActivity(new Intent(this, Curriculum_Activity.class));
                break;
        }
    }
}
